package client;

import javax.swing.*;
import java.util.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;


/**
 * Created by IntelliJ IDEA.
 * User: Hp
 * Date: 17.04.11
 * Time: 12:55
 * To change this template use File | Settings | File Templates.
 */
public class Painter extends JApplet {
    public void init(){
        setSize(400,300);
        PainterPanel panel=new PainterPanel(this.getWidth(),this.getHeight());
        add(panel);
    }

}
class PainterPanel extends JPanel{
    List<Point> points =new ArrayList<Point>();
    Point stop=new Point(-1,-1);
    MouseAdapter ma=new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            points.add(e.getPoint());
            repaint();
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            points.add(e.getPoint());
            points.add(stop);
            repaint();
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            points.add(e.getPoint());
            points.add(stop);
            repaint();
        }

        @Override
        public void mouseDragged(MouseEvent e) {
            points.add(e.getPoint());
            repaint();
        }
    };
    int width,height;

    public PainterPanel(int size_width, int size_height){
        width=size_width;
        height=size_height;

        setLocation(0,0);
        addMouseListener(ma);
        addMouseMotionListener(ma);


    }
    public void paintComponent(Graphics g){
        g.drawLine(1,1,1,height-1);
        g.drawLine(1,1,width-1,1);
        g.drawLine(width-1,1,width-1,height-1);
        g.drawLine(1,height-1,width-1,height-1);
         for(int i=1;i<points.size();i++){
             if(points.get(i)==stop || points.get(i-1)==stop)continue;
             g.drawLine(points.get(i-1).x,points.get(i-1).y,points.get(i).x,points.get(i).y);
         }
    }
}
class PaintSettingsPanel extends JPanel{

}
class ConnectionSettingsPanel extends JPanel{

}
